/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.registration.gui.security;

import it.polimi.registration.business.security.boundary.UserManager;
import it.polimi.registration.business.security.boundary.WeatherService;
import it.polimi.registration.business.security.entity.Event;
import java.io.IOException;
import java.io.Serializable;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;
import net.aksingh.owmjapis.AbstractWeather.Weather;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.json.JSONException;

/**
 *
 * @author Stefano
 */
@Named
@RequestScoped
public class WeatherBean {

    @EJB
    WeatherService w;
    
    @Inject
    private UserManager um;

    @Inject
    private EventBean eb;
    
    private int weather;
    private String weatherDescription;
    
    public int weather(String city, Date date){
        try {
                weather=w.weatherService(city, date);
        } catch (IOException ex) {
            Logger.getLogger(LoginBean.class.getName()).log(Level.SEVERE, null, ex);
        } catch (JSONException ex) {
            Logger.getLogger(LoginBean.class.getName()).log(Level.SEVERE, null, ex);
        }
        return weather;
    }
    
    public String getWeatherDescription(int code){
        w.WeatherCheck(code);
        weatherDescription = w.getdescription();
        return weatherDescription;
    }
    
    public void checkWeatherEvent(Event event) throws IOException{
        System.out.println("cerco se c'è brutto tempo per quest'evento");
        w.checkWeatherEvent(event);
    }
}
